package com.cuit.zuke.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cuit.zuke.common.util.Result;
import com.cuit.zuke.product.model.entity.Goods;
import com.cuit.zuke.product.model.entity.Warehouse;
import com.cuit.zuke.product.model.vo.StockQueryVO;
import com.cuit.zuke.product.model.vo.StockVO;
import com.cuit.zuke.product.model.vo.WarehouseVO;
import com.cuit.zuke.product.service.GoodsService;
import com.cuit.zuke.product.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product/warehouse")
public class WarehouseController {

    @Autowired
    private WarehouseService warehouseService;

    @Autowired
    private GoodsService goodsService;

    @GetMapping(value = "list/{page}/{limit}")
    public Result listWarehouse(@PathVariable Integer page,
                            @PathVariable Integer limit){
        Page<WarehouseVO> warehousePage = warehouseService.findPage(page,limit);
        return Result.ok().put("data",warehousePage);
    }

    @GetMapping(value = "/findAll")
    public Result listWarehouse(){
        List<Warehouse> warehouseList = warehouseService.findAll();
        List<Goods> list = goodsService.list();
        return Result.ok().put("warehouseList",warehouseList).put("goodsList",list);
    }

    @GetMapping(value = "/findAllCli")
    public List<Warehouse> listWarehouseCli(){
        List<Warehouse> warehouseList = warehouseService.findAll();
        return warehouseList;
    }

    @GetMapping(value = "getNameById/{warehouseId}")
    String getWarehouseNameByIdCli(@PathVariable("warehouseId") Integer warehouseId){
        String fullLocNameById = warehouseService.getFullLocNameById(warehouseId);
        return fullLocNameById;
    }

}
